﻿using StudySystem.MainLogic.FormControl;
using StudySystem.MainLogic.Items;
using System;
using System.Data;
using System.Windows.Forms;

namespace StudySystem.Windows
{
    public partial class FormModifyQues : Form
    {
        ClassQuestion question;
        Question qItem;
        public FormModifyQues()
        {
            InitializeComponent();
        }
        public FormModifyQues(ClassQuestion q, Question qItem)
        {
            InitializeComponent();
            question = q;
            this.qItem = qItem;
        }
        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (!FormController.CheckQuestion(richTxtQuestion.Text, richTxtAnswer.Text))
            {
                MessageBox.Show("未检测到有效内容，请重新输入！");
            }
            else
            {
                question.ModifyAQuestion(richTxtQuestion.Text, richTxtAnswer.Text);
                this.Hide();
                DialogResult dialogResult = MessageBox.Show("问题修改成功！");
                if(dialogResult == DialogResult.OK)
                {
                    FormQuesControl.ModifyAQuestion(qItem, richTxtQuestion.Text, richTxtAnswer.Text);
                    this.Close();
                }
            }

        }

        private void richTxtQuestion_TextChanged(object sender, EventArgs e)
        {

        }

        private void FormModifyQues_Load(object sender, EventArgs e)
        {
            richTxtQuestion.Text = question.QuestionContent;
            richTxtAnswer.Text = question.Answer;
        }
    }
}
